package org.leecode.h1to10;

public class problem88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int idx = m+n-1;
        int i = m-1,j = n-1;
        while(i>=0 && j>=0){
            if(nums1[i]<nums2[j]){
                nums1[idx--] = nums2[j--];
            }else {
                nums1[idx--] = nums1[i--];
            }
        }
        while(j>=0){
            nums1[idx--] = nums2[j--];
        }
    }

    public static void main(String[] args) {
        int[] nums1 = new int[]{1, 2, 3, 0, 0, 0};
        int[] nums2 = new int[]{2, 5, 6};
        problem88 m = new problem88();
        m.merge(nums1, 3, nums2, 3);
    }
}
